﻿Imports System.Data.SqlClient

Public Class clsE_Ventas
    Private mintIdVenta As Integer
    Private mintIdAutobus As Integer
    Private mstrNoEconomico As String
    Private mintIdOperador As Integer
    Private mstrNombreOperador As String
    Private mdatFecha As Date
    Private mintDia As Integer
    Private mintMes As Integer
    Private mintAnio As Integer
    Private mintIdLiquidacion As Integer
    Private mdblLiquidacion As Double
    Private mdblOptocontrol As Double
    Private mdblDiferencia As Double
    Private mintMetaV As Integer
    Private mintMovilidad As Integer
    Private mintBloqueos As Integer
    Private mdblPorcentaje As Double
    Private mintMetaB As Integer
    Public Property IdVenta() As Integer
        Get
            Return mintIdVenta
        End Get
        Set(ByVal value As Integer)
            mintIdVenta = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property

    Public Property NoEconomico() As String
        Get
            Return mstrNoEconomico
        End Get
        Set(ByVal value As String)
            mstrNoEconomico = value
        End Set
    End Property
    Public Property IdOperador() As Integer
        Get
            Return mintIdOperador
        End Get
        Set(ByVal value As Integer)
            mintIdOperador = value
        End Set
    End Property
    Public Property NombreOperador() As String
        Get
            Return mstrNombreOperador
        End Get
        Set(ByVal value As String)
            mstrNombreOperador = value
        End Set
    End Property
    Public Property Fecha() As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Dia() As Integer
        Get
            Return mintDia
        End Get
        Set(ByVal value As Integer)
            mintDia = value
        End Set
    End Property
    Public Property Mes() As Integer
        Get
            Return mintMes
        End Get
        Set(ByVal value As Integer)
            mintMes = value
        End Set
    End Property
    Public Property Anio() As Integer
        Get
            Return mintAnio
        End Get
        Set(ByVal value As Integer)
            mintAnio = value
        End Set
    End Property
    Public Property IdLiquidacion() As Integer
        Get
            Return mintIdLiquidacion
        End Get
        Set(ByVal value As Integer)
            mintIdLiquidacion = value
        End Set
    End Property
    Public Property Liquidacion() As Double
        Get
            Return mdblLiquidacion
        End Get
        Set(ByVal value As Double)
            mdblLiquidacion = value

        End Set
    End Property
    Public Property Optocontrol() As Double
        Get
            Return mdblOptocontrol
        End Get
        Set(ByVal value As Double)
            mdblOptocontrol = value

        End Set
    End Property
    Public Property Diferencia() As Double
        Get
            Return mdblDiferencia
        End Get
        Set(ByVal value As Double)
            mdblDiferencia = value

        End Set
    End Property
    Public Property MetaV() As Integer
        Get
            Return mintMetaV
        End Get
        Set(ByVal value As Integer)
            mintMetaV = value
        End Set
    End Property
    Public Property Movilidad() As Integer
        Get
            Return mintMovilidad
        End Get
        Set(ByVal value As Integer)
            mintMovilidad = value
        End Set
    End Property
    Public Property Bloqueos() As Integer
        Get
            Return mintBloqueos
        End Get
        Set(ByVal value As Integer)
            mintBloqueos = value
        End Set
    End Property
    Public Property Porcentaje() As Double
        Get
            Return mdblPorcentaje
        End Get
        Set(ByVal value As Double)
            mdblPorcentaje = value

        End Set
    End Property
    Public Property MetaB() As Integer
        Get
            Return mintMetaB
        End Get
        Set(ByVal value As Integer)
            mintMetaB = value
        End Set
    End Property
    Public Sub New()
        mintIdVenta = 0
        mintIdAutobus = 0
        mstrNoEconomico = ""
        mintIdOperador = 0
        mstrNombreOperador = ""
        mdatFecha = Now()
        mintDia = 0
        mintMes = 0
        mintAnio = 0
        mintIdLiquidacion = 0
        mdblLiquidacion = 0
        mdblOptocontrol = 0
        mdblDiferencia = 0
        mintMetaV = 0
        mintMovilidad = 0
        mintBloqueos = 0
        mdblPorcentaje = 0
        mintMetaB = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into E_Ventas (" & _
                            "IdAutobus," & _
                            "NoEconomico," & _
                            "IdOperador," & _
                            "NombreOperador," & _
                            "Fecha," & _
                            "Dia," & _
                            "Mes," & _
                            "Anio," & _
                            "IdLiquidacion," & _
                            "Liquidacion," & _
                            "Optpcontrol," & _
                            "Diferencia," & _
                            "MetaV," & _
                            "Movilidad," & _
                            "Bloqueos," & _
                            "Porcentaje," & _
                            "MetaB) " & _
                            "VALUES (" & _
                            "@IdAutobus," & _
                            "substring(@NoEconomico,1,100)," & _
                            "@IdOperador," & _
                            "substring(@NombreOperador,1,150)," & _
                            "@Fecha," & _
                            "@Dia," & _
                            "@Mes," & _
                            "@Anio," & _
                            "@IdLiquidacion," & _
                            "@Liquidacion," & _
                            "@Optocontrol," & _
                            "@Diferencia," & _
                            "@MetaV," & _
                            "@Movilidad," & _
                            "@Bloqueos," & _
                            "@Porcentaje," & _
                            "@MetaB) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Dia", mintDia)
        Command.Parameters.AddWithValue("Mes", mintMes)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("IdLiquidacion", mintIdLiquidacion)
        Command.Parameters.AddWithValue("Liquidacion", mdblLiquidacion)
        Command.Parameters.AddWithValue("Optocontrol", mdblOptocontrol)
        Command.Parameters.AddWithValue("Diferencia", mdblDiferencia)
        Command.Parameters.AddWithValue("MetaV", mintMetaV)
        Command.Parameters.AddWithValue("Movilidad", mintMovilidad)
        Command.Parameters.AddWithValue("Bloqueos", mintBloqueos)
        Command.Parameters.AddWithValue("Porcentaje", mdblPorcentaje)
        Command.Parameters.AddWithValue("MetaB", mintMetaB)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de ventas", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update E_Ventas Set " & _
                            "IdAutobus=@IdAutobus," & _
                            "NoEconomico=substring(@NoEconomico,1,50)," & _
                            "IdOperador=@IdOperador," & _
                            "NombreOperador=substring(@NombreOperador,1,50)," & _
                            "Fecha=@Fecha," & _
                            "Dia=@Dia," & _
                            "Mes=@Mes," & _
                            "Anio=@Anio," & _
                            "IdLiquidacion=@IdLiquidacion," & _
                            "Liquidacion=@Liquidacion," & _
                            "Optpcontrol=@Optocontrol," & _
                            "Diferencia=@Diferencia," & _
                            "MetaV=@MetaV," & _
                            "Movilidad=@Movilidad," & _
                            "Bloqueos=@Bloqueos," & _
                            "Porcentaje=@Porcentaje," & _
                            "MetaB=@MetaB " & _
                            " Where IdVenta=@IdVenta"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("IdVenta", mintIdVenta)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Dia", mintDia)
        Command.Parameters.AddWithValue("Mes", mintMes)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("IdLiquidacion", mintIdLiquidacion)
        Command.Parameters.AddWithValue("Liquidacion", mdblLiquidacion)
        Command.Parameters.AddWithValue("Optocontrol", mdblOptocontrol)
        Command.Parameters.AddWithValue("Diferencia", mdblDiferencia)
        Command.Parameters.AddWithValue("MetaV", mintMetaV)
        Command.Parameters.AddWithValue("Movilidad", mintMovilidad)
        Command.Parameters.AddWithValue("Bloqueos", mintBloqueos)
        Command.Parameters.AddWithValue("Porcentaje", mdblPorcentaje)
        Command.Parameters.AddWithValue("MetaB", mintMetaB)

        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el registro de ventas", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
End Class
